package com.qiantu.phone.utils;

import android.util.Log;

import java.util.HashMap;
import java.util.Map;

/**
 *
 */
public class DataHolder {
    private Map dataList = new HashMap<>();
    private static volatile DataHolder instance;

    public static DataHolder getInstance() {
        if (instance == null) {
            synchronized (DataHolder.class) {
                if (instance == null) {
                    instance = new DataHolder();
                }
            }
        }
        return instance;
    }

    public void setData(String key, Object o) {
        Log.i("lzxlzx", "setData:" + o);
//        WeakReference value = new WeakReference<>(o);
        dataList.put(key, o);
    }

    public void clearData(String key){
        Log.i("lzxlzx", "clearData");
        dataList.remove(key);
    }

    public Object getData(String key) {
//        WeakReference reference = (WeakReference) dataList.get(key);
//        if (reference != null) {
//            Object o = reference.get();
//            Log.i("lzxlzx", "getData:" + o);
//            return o;
//        }
//        return null;
        return dataList.get(key);
    }

}